"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

exports.default = function (results) {
  var output = (0, _stringFormatter2.default)(results);

  if (output === "") {
    output = "\n";
  }

  var sourceWord = results.length > 1 ? "sources" : "source";
  var ignoredCount = results.filter(function (result) {
    return result.ignored;
  }).length;
  var checkedDisplay = ignoredCount ? results.length - ignoredCount + " of " + results.length : results.length;
  output += _chalk2.default.underline(checkedDisplay + " " + sourceWord + " checked\n");
  results.forEach(function (result) {
    var formatting = "green";
    if (result.errored) {
      formatting = "red";
    } else if (result.warnings.length) {
      formatting = "yellow";
    } else if (result.ignored) {
      formatting = "dim";
    }
    var sourceText = "" + result.source;
    if (result.ignored) {
      sourceText += " (ignored)";
    }
    output += _lodash2.default.get(_chalk2.default, formatting)(" " + sourceText + "\n");
  });

  var warnings = _lodash2.default.flatten(results.map(function (r) {
    return r.warnings;
  }));
  var warningsBySeverity = _lodash2.default.groupBy(warnings, "severity");
  var problemWord = warnings.length === 1 ? "problem" : "problems";

  output += _chalk2.default.underline("\n" + warnings.length + " " + problemWord + " found\n");

  _lodash2.default.forOwn(warningsBySeverity, function (warningList, severityLevel) {
    var warningsByRule = _lodash2.default.groupBy(warningList, "rule");
    output += " severity level \"" + severityLevel + "\": " + warningList.length + "\n";
    _lodash2.default.forOwn(warningsByRule, function (list, rule) {
      output += _chalk2.default.dim("  " + rule + ": " + list.length + "\n");
    });
  });

  return output + "\n";
};

var _lodash = require("lodash");

var _lodash2 = _interopRequireDefault(_lodash);

var _chalk = require("chalk");

var _chalk2 = _interopRequireDefault(_chalk);

var _stringFormatter = require("./stringFormatter");

var _stringFormatter2 = _interopRequireDefault(_stringFormatter);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }